package edu.ustb.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import edu.ustb.domain.Brand;
import edu.ustb.domain.Goods;
import edu.ustb.service.BrandService;
import edu.ustb.service.BrandServiceImpl;
import edu.ustb.service.GoodsSearchService;
import edu.ustb.service.GoodsSearchServiceImpl;

/**
 * Servlet implementation class GoodsDetailController
 */
@WebServlet("/goodsdetail.do")
public class GoodsDetailController extends HttpServlet {
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String goodsId = request.getParameter("goodsId");
		
		GoodsSearchService goodsSearchService = new GoodsSearchServiceImpl();
		BrandService brandService = new BrandServiceImpl();
		Goods goods = goodsSearchService.findGoodsById(goodsId);
		Brand brand = brandService.findBrandById(goods.getGoodsBrandId());
		
		request.setAttribute("goods", goods);
		request.setAttribute("brand", brand);
		request.getRequestDispatcher("details.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
